/**
 * Created by smp on 2017/4/10.
 */
var handleJudge="noHandle";
function validColor() {
    var flag=true;
    $(".validColor").each(function () {
        var len=$(this).parent("li").siblings("li").children(".judgeT:checked").length;
        console.log(len);
        if(len==0){
            flag=false;
        }
    });
    return flag;
}

$('#cardSave').on('click',function () {
    var index=layer.confirm('是否确定保存？', {
        btn: ['确定','取消'] //按钮
    }, function(){
        var fl=validColor();
        if(fl==false){
            layer.close(index);
            layer.msg('带*号的必填', {
                icon: 2,
                time: 2000
            });
            return;
        }
        if(handleJudge=="noHandle"){
            if($("#handleOpinion").textbox("getValue")==null||$("#handleOpinion").textbox("getValue")==""){
                layer.close(index);
                layer.msg('带*号的必填', {
                    icon: 2,
                    time: 2000
                });
                return;
            }
        }else {
            if($("#handlePeople").val()==null||$("#handlePeople").val()==""){
                layer.close(index);
                layer.msg('带*号的必填', {
                    icon: 2,
                    time: 2000
                });
                return;
            }
        }
        $('#cardForm').form('submit', {
            url: ROOT_PATH+'/observation/observationCard/analysisCard.shtml',
            onSubmit: function (param) {
                var isValid = $(this).form('validate');
                if (!isValid) {
                    layer.close(index);
                    layer.msg("请正确填写表单")
                }
                return $(this).form('validate');
            },
            success: function (result) {
                result = $.parseJSON(result);
                if (result.success){
                    //$.messager.progress('close');	// 如果提交成功则隐藏进度条
                    parent.layer.msg(result.message,{time:1000,icon:1},function () {
                        parent.$('#dg1').datagrid('load');
                        parent.layer.closeAll(); //先得到当前iframe层的索引
                    });
                }else {
                    //$.messager.progress('close');	// 如果提交成功则隐藏进度条
                    parent.layer.msg(result.message,{time:1000,icon:2});
                }
            }
        });
    });

});
//表单驳回
$('#cardBack').on('click',function () {
    var index=layer.confirm('是否确定保存？', {
        btn: ['确定','取消'] //按钮
    }, function(){
        $('#cardForm').form('submit', {
            url: ROOT_PATH+'/observation/observationCard/reject.shtml',
            onSubmit: function (param) {
                var isValid = $(this).form('validate');
                if (!isValid) {
                    layer.close(index);
                    layer.msg("请正确填写表单")
                }
                return $(this).form('validate');
            },
            success: function (result) {
                result = $.parseJSON(result);
                if (result.success){
                    //$.messager.progress('close');	// 如果提交成功则隐藏进度条
                    parent.layer.msg(result.message,{time:1000,icon:1},function () {
                        parent.$('#dg1').datagrid('load');
                        parent.layer.closeAll(); //先得到当前iframe层的索引
                    });
                }else {
                    //$.messager.progress('close');	// 如果提交成功则隐藏进度条
                    parent.layer.msg(result.message,{time:1000,icon:2});
                }
            }
        });
    });

});
//参数清空
$('#cardReset').on('click',function () {
    $('#cardForm').form('reset');
});

$("#yesHandle").click(function () {
    $("#handleUserTabel").css("display","block");
    $("#handleDoTabel").css("display","none");
    $(".handleUserText").css("display","block");
    $(".handleDoText").css("display","none");
    handleJudge="yesHandle";
});
$("#noHandle").click(function(){
    $("#handleUserTabel").css("display","none");
    $("#handleDoTabel").css("display","block");
    $(".handleDoText").css("display","block");
    $(".handleUserText").css("display","none");
    handleJudge="noHandle";
});
var getSelectedUser = function (data) {
        $("#handlePeople").val(data[0].id);
        $("#handlePeopleName").textbox("setValue",data[0].realName);
};
$('#handlePeopleName').textbox({
    icons: [{
        iconCls: 'icon-search',
        handler: function () {
            WindowManager.openLayer({
                type: 2,
                title: '添加处理人',
                area: ['90%', '70%'],
                content: ROOT_PATH + '/permission/user/simpleList.shtml?isMulti=0',
                callBack:getSelectedUser
            });
        }
    }],
    editable: false
});